// optional Properties

interface Shape {}

interface PaintOptions {
    shape: Shape;
    xPos?: number;
    yPos?: number;
}

function paintShape(opts: PaintOptions) {
    // ...
}

let shape!: Shape;

paintShape({ shape });
paintShape({ shape, xPos: 100 });
paintShape({ shape, yPos: 100 });
paintShape({ shape, xPos: 100, yPos: 100 });

// readonly Properties

interface SomeType {
    readonly prop: string;
}

function doSomeThing(obj: SomeType) {
    console.log(`Prop has the value '${obj.prop}'.`);

    // Cannot assign to 'prop' because it is a read-only property.
    // obj.prop = 'hello';
}

interface Person {
    name: string;
    age: number;
}

interface ReadOnlyPerson {
    readonly name: string;
    readonly age: number;
}

let writablePerson: Person = {
    name: 'Person One',
    age: 22
};

let readonlyPerson: ReadOnlyPerson = writablePerson;

let writablePerson2: Person = readonlyPerson;

// Index Signatures

interface StringArray {
    [index: number]: string;
}

let myArray!: StringArray;
let elem = myArray[0]; // string

interface NumberOrDictionary {
    [index: string]: number | string;

    length: number;
    name: string;
}

interface ReadonlyStringArray {
    readonly [index: number]: string;
  }

let myArray2!: ReadonlyStringArray;

// 类型“ReadonlyStringArray”中的索引签名仅允许读取。
// myArray2[2] = 'Mallory';

export {};